<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="libs/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="css/index.css">
    <script src="libs/jquery-3.4.1.min.js"></script>
    <script src="libs/bootstrap/js/bootstrap.min.js"></script>
    <script src="js/utils.js"></script>
    <title>Mr丶小店</title>
</head>

<body>
    <nav class="navbar navbar-inverse">
        <div class="container">
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li><a class="navbar-brand" href="#">Mr丶先生</a></li>
                    <li><a href="#" class="label label-default">首页</a></li>
                    <li><a href="#">其他页面</a></li>
                </ul>
                <ul class="nav navbar-nav navbar-right show" id="u1">
                    <li><a href="#" class="btn btn-lg" data-toggle="modal" data-target="#loginModal" id="zybtn">登录</a></li>
                    <li><a href="#" class="btn btn-lg" data-toggle="modal" data-target="#registModal">注册</a></li>
                </ul>
                <ul class="nav navbar-nav navbar-right hidden" id="u2">
                    <li><a href="#">欢迎您   <b id="bname"></b></a></li>
                    <li><a href="#" id="userclose">注销</a></li>
                </ul>
            </div>
        </div>
    </nav>
    <div class="container">
        <button type="button" class="btn btn-lg btn btn-primary btn-sm addbtn" data-toggle="modal" data-target="#addModal">添加商品</button>
        <table class="table table-striped table-bordered table-hover table-condensed table-shop" id="table-sg">
            <thead>
                <tr>
                    <td>编号</td>
                    <td>商品名称</td>
                    <td>商品价格</td>
                    <td>商品数量</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody id="list-tbody">
                <!-- <tr>
                    <td>1</td>
                    <td><span>生发剂</span><input type="text"></td>
                    <td><span>99</span><input type="text"></td>
                    <td><span>2</span><input type="text"></td>
                    <td>
                        <button class="btn btn-info btn btn-primary btn-xs btn-edit">编辑</button>
                        <button class="btn btn-danger btn btn-primary btn-xs btn-del">删除</button>
                        <button class="btn btn-success btn btn-primary btn-xs btn-ok">确定</button>
                        <button class="btn btn-warning btn btn-primary btn-xs btn-cancel">取消</button>
                    </td>
                </tr>
                <tr>
                    <td>1</td>
                    <td><span>生发剂</span><input type="text"></td>
                    <td><span>99</span><input type="text"></td>
                    <td><span>2</span><input type="text"></td>
                    <td><button class="btn btn-info btn btn-primary btn-xs btn-edit">编辑</button>
                        <button class="btn btn-danger btn btn-primary btn-xs btn-del">删除</button>
                        <button class="btn btn-success btn btn-primary btn-xs btn-ok">确定</button>
                        <button class="btn btn-warning btn btn-primary btn-xs btn-cancel">取消</button></td>
                </tr>
                <tr>
                    <td>1</td>
                    <td><span>生发剂</span><input type="text"></td>
                    <td><span>99</span><input type="text"></td>
                    <td><span>2</span><input type="text"></td>
                    <td><button class="btn btn-info btn btn-primary btn-xs btn-edit">编辑</button>
                        <button class="btn btn-danger btn btn-primary btn-xs btn-del">删除</button>
                        <button class="btn btn-success btn btn-primary btn-xs btn-ok">确定</button>
                        <button class="btn btn-warning btn btn-primary btn-xs btn-cancel">取消</button></td>
                </tr> -->
            </tbody>
        </table>
    </div>
    <!-- Modal -->
    <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog " role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">添加商品</h4>
                </div>
                <div class="modal-body form-horizontal">
                    <div class="form-group">
                        <label for="inputName" class="col-sm-2 control-label">商品名称</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="inputName" placeholder="请输入商品名称">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputPrice" class="col-sm-2 control-label">商品价格</label>
                        <div class="col-sm-10">
                            <input type="number" class="form-control" id="inputPrice" placeholder="请输入商品价格">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputNum" class="col-sm-2 control-label">商品数量</label>
                        <div class="col-sm-10">
                            <input type="number" class="form-control" id="inputNum" placeholder="请输入商品数量">
                        </div>
                    </div>
                    <p id="add-info" class="text-center"></p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" id="btn-add">添加</button>
                </div>
            </div>
        </div>
    </div>
    <!-- 登录 -->
    <!-- Modal -->
    <div class="modal fade" id="loginModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">

                <div class="modal-header">
                    <h4 class="modal-title" id="myModalLabel">登录</h4>
                </div>
                <div class="modal-body">


                    <form class="form-horizontal" action="api/v1/user/login.php" method="GET">
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">账号</label>
                            <div class="col-sm-10">
                                <input type="email" class="form-control" name="username" id="login-name" placeholder="请您输入账号">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputPassword3" class="col-sm-2 control-label">密码</label>
                            <div class="col-sm-10">
                                <input type="password" class="form-control" name="password" id="login-pwd" placeholder="请输入密码">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <div class="checkbox">
                                    <label>
                                <input type="checkbox" id="yz"> 记住密码
                                <p class="xp hidden">您输入的账号密码有误！请重新输入</p>
                                <span class="xp1 hidden">登录成功！</span>

                              </label>
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary" id="login-btn">登录</button>
                        </div>
                    </form>
                </div>

            </div>
        </div>
    </div>
    <!-- 注册 -->
    <div class="modal fade" id="registModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="myModalLabel">注册</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal">
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">账号</label>
                            <div class="col-sm-10">
                                <input type="email" class="form-control" name="username" id="register-name" placeholder="请您输入账号">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputPassword3" class="col-sm-2 control-label">密码</label>
                            <div class="col-sm-10">
                                <input type="password" class="form-control" name="password" id="register-pwd" placeholder="请输入密码">
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary" id="register-btn">注册</button>
                        </div>
                    </form>
                </div>

                <script src="js/select.js"></script>
                <script src="js/add.js"></script>
                <!-- <script src="js/delete.js"></script> -->
                <!-- <script src="js/edit.js"></script> -->

                <script>
                    tbody.onclick = function(e) {
                        console.log(e);

                        if (e.target.className == "btn btn-info btn btn-primary btn-xs btn-edit") {
                            let tr = e.target.parentNode.parentNode
                            tr.classList.add('edit')
                            let input = document.getElementsByClassName('a');
                            for (let i = 0; i < input.length; i++) {
                                //获取上一级兄弟元素
                                //把span的值赋给Input
                                input[i].value = input[i].previousElementSibling.innerHTML;
                            }
                        }
                        //成功
                        if (e.target.className == "btn btn-success btn btn-primary btn-xs btn-ok") {
                            let input = document.getElementsByClassName('a');
                            let id = e.target.parentNode.parentNode.getAttribute("data-id");
                            let bh = e.target.parentNode.parentNode.firstElementChild.innerHTML;
                            console.log(bh);
                            //传值给后台
                            utils.fetch("api/v1/shop/edit.php", {
                                id,
                                name: input[(bh - 1) * 3].value,
                                price: input[(bh - 1) * 3 + 1].value,
                                num: input[(bh - 1) * 3 + 2].value
                            }).then((resp) => {
                                console.log(resp);
                            })
                            let tr = e.target.parentNode.parentNode
                            tr.classList.remove('edit')
                            getDate();
                        }
                        //取消
                        if (e.target.className == "btn btn-warning btn btn-primary btn-xs btn-cancel") {
                            let tr = e.target.parentNode.parentNode
                            tr.classList.remove('edit')
                        }
                        //删除
                        if (e.target.className == "btn btn-danger btn btn-primary btn-xs btn-del") {
                            let tr = e.target.parentNode.parentNode

                            let id = tr.getAttribute('data-id')
                            console.log(id);
                            utils.fetch('./api/v1/shop/delete.php', {
                                id
                            }).then((resp) => {
                                console.log(resp);

                            })
                            getDate();
                        }
                    }
                </script>

                <script src="js/login.js"></script>
                <script src="js/register.js"></script>
                <script>
                    // console.log(info.username);
                </script>

</body>

</html>